# 指定CMake版本要求
cmake_minimum_required(VERSION 3.0.0)

# 定义项目名称
project(C_PYTHON_JSON_PARSE VERSION 0.1.0)

# 指定C++版本, std::function要求C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 指定执行文件的源文件
aux_source_directory(${PROJECT_SOURCE_DIR} EXE_SRC_LIST)

# 指定Python环境变量
if( APPLE )
    set(PYTHON_PATH "/Library/Frameworks/Python.framework/Versions/3.8")
    include_directories("${PYTHON_PATH}/include/python3.8")
    set(PythonLibName "python3.8")

    # 指定链接目录
    link_directories("${PYTHON_PATH}/lib")
else()
    set(PYTHON_PATH $ENV{PY38BIN})
    if(NOT DEFINED PYTHON_PATH)
        message(FATAL "PY38执行目录未设置")
    endif()
    include_directories("${PYTHON_PATH}/include")
    set(PythonLibName "python38")

    # 指定链接目录
    link_directories("${PYTHON_PATH}/libs")
endif()

# 指定执行文件名
set(EXE_NAME main)

# 生成执行文件
add_executable(${EXE_NAME} ${EXE_SRC_LIST})

# 执行文件链接所需库文件
target_link_libraries(${EXE_NAME} ${PythonLibName})
